﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using DigDes.DS2012.BusinessLogic;

namespace DigDes.DS2012.WebUI
{
    public class Selector : DropDownList
    {
        public enum TypeOf { Int, Str };

        private string storedProcedureName = "";

        public Selector(string name, string storedProcedureName) : base()
        {
            var locManager = new DislocationHistoryManager();

            this.storedProcedureName = storedProcedureName;
            this.ID = name;
            this.Width = 200;

            this.Items.Add(new ListItem("<Все>"));

            foreach (var tmpStr in locManager.GetReference(storedProcedureName))
                this.Items.Add(new ListItem(tmpStr));
        }

        public static string GetValue(Selector selector, TypeOf type)
        {
            return (selector.SelectedValue == "<Все>") ? ((type == TypeOf.Int) ? "-1/" : "") : selector.SelectedValue;
        }
    }
}